import Vue from 'vue'
import Vuex from 'vuex'

Vue.use(Vuex)

const store = new Vuex.Store({
  state: {
		vuex_user:  {},
		collapsed:  false,
		vuex_meun_name:  '',
		// vuex_src:  'http://192.168.0.103:3000/upload/',
		vuex_src: 'https://admin.lhlzgroup.com/upload/',
		// vuex_url: 'http://192.168.0.103:3000/api/code',
		vuex_url: 'https://admin.lhlzgroup.com/api/code',
	},
  mutations: {
		$cStore(state, payload) {
			// 判断是否多层级调用，state中为对象存在的情况，诸如user.info.score = 1
			let nameArr = payload.name.split('.');
			let saveKey = '';
			let len = nameArr.length;
			if(len >= 2) {
				let obj = state[nameArr[0]];
				for(let i = 1; i < len - 1; i ++) {
					obj = obj[nameArr[i]];
				}
				obj[nameArr[len - 1]] = payload.value;
				saveKey = nameArr[0];
			} else {
				// 单层级变量，在state就是一个普通变量的情况
				state[payload.name] = payload.value;
				saveKey = payload.name;
			}
		},
  },
  actions: {
  },
  modules: {
  }
})

export default store